﻿
$(function () {
    //初始化列表信息
    init();
});

//初始化列表信息
function init(queryData) {
    $('#list').datagrid({
        title: '个人通讯录类别',
        idField: 'ContactsKindID',
        fitColumns: 'true',
        autoRowHeight: true,
        nowrap: true,
        striped: true,
        pagination: true,
        url: 'ContactsKind/GetList',
        columns: [[
			{ field: 'ck', checkbox: true },
			{ field: 'ContactsKindID', title: 'ContactsKind', hidden: true},
			{ field: 'ContactsKindName', title: 'ContactsKindName', width: 180},
			{ field: 'OwnerUserID', title: 'OwnerUserID', width: 180},
		
        ]],
    });
}

//弹出增加窗口
function add() {
    $('#dlg').dialog('open').dialog('setTitle', '增加');
    $('#fm').form('clear');
    url = '/ContactsKind/Create';
}

//弹出修改窗口
function edit() {
    var row = $('#list').datagrid('getSelected');
    if (row) {
        $('#dlg').dialog('open').dialog('setTitle', '修改');
        $('#fm').form('load', row);
        url = '/ContactsKind/Edit';
    }
}

//保存数据
function save() {
    $('#fm').form('submit', {
        url: url,
        onSubmit: function () {
            return $(this).form('validate');
        },
        success: function (result) {
            if (result == 'OK') {
                $('#dlg').dialog('close');      // close the dialog  
                $('#list').datagrid('reload');    // reload the user data  
            } else {
                $.messager.show({
                    title: 'Error',
                    msg: result
                });
            }
        }
    });
}

//删除
function del() {
    var rows = $('#list').datagrid('getSelected');
    if (rows) {
        $.messager.confirm(delDlgTitle, delDlgMsg, function (r) {
            if (r) {
                $.post('/ContactsKind/Delete', { id: rows.ContactsKindID },
                    function (result) {
                        if (result == 'OK') {
                            $("#list").datagrid('clearSelections');
                            $('#list').datagrid('reload');    // reload the user data  
                        } else {
                            $.messager.show({   // show error message  
                                title: 'Error',
                                msg: result
                            });
                        }
                    });
            }
        });
    }
}